<!-- YYY  -->

<?php 

$allReport  = $this->allReport;
$all_overtime = $all_total = $sum_total = 0;
//print_r($this->view);
//die;

if ('close' == $this->reportPeriod['status'])
    {
?>
<input type="hidden" id="period_status" value="close" />
<?php     	
    }
?>
<table border="0" id="table1">
     <tr class="tr1">
        <th class="tr0">Name:</th>
        <th> &nbsp; <?php echo $this->user->name; ?> &nbsp;</th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
        <th> &nbsp; Afkorting: &nbsp;</th>
        <th> &nbsp; <?php echo $this->user->afk; ?> &nbsp;</th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
        <th> &nbsp; Periode: &nbsp; </th>
        <th> &nbsp; <?php echo $this->period; ?> &nbsp; </th>
        <th> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </th>
<?php if ('print' != $this->views) {?>        
        <th> &nbsp; View: &nbsp; </th>
        <th  class="project_name"> 
            <select name="archive" id="archive">
            <option name="">Current month</option>
            <?php
                foreach ($this->archiveDate as $date)
                {
                	$select = $this->archive == $date ? 'selected="selected"' : '';
                	echo '<option name="' . $date . '" ' . $select . '>' . $date .'</option>' . "\n";
                } 
            ?>
            </select>
         </th>
         <th class="project_name"> &nbsp;         <?php 
            if (isset($this->attach))
            {
        ?>
                <a href="/attach/<?php echo $this->attach['file_name']?>" target="_blank" class="sexybutton sexysimple sexygreen">View timesheet</a>
        <?php 
            }?>  </th>
         <th class="project_name">
            <form action="/index/pdf" method="post">
	            <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
	            <input type="hidden" name="view" value="print" />
	            <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
	            <input type="hidden" name="month" value="<?php echo $this->month; ?>" />   
	            <input type="hidden" name="archive" value="<?php echo $this->archive; ?>" />
	            <input type="submit" class="sexybutton sexysimple sexygreen " value="Print report" />   
            </form> 
         </th>   
         <th class="project_name">
          <?php if ('close' != $this->reportPeriod['status']) {?>
		        <form action="/index/period" method="post">
		            <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
		            <input type="hidden" name="do_action" value="close" />
		            <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
		            <input type="hidden" name="month" value="<?php echo $this->month; ?>" />          
		            <input type="submit" class="sexybutton sexysimple sexyred"  value="Close period" />   
		        </form> 
		    <?php } ?>
         </th>
         
         <th class="project_name">
          <?php // if ('close' != $this->reportPeriod['status']) {?>
                <form action="/index/addproject" method="post" >
                    <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
                    <input type="hidden" name="do_action" value="close" />
                    <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
                    <input type="hidden" name="month" value="<?php echo $this->month; ?>" />          
                    <input type="submit" class="sexybutton sexysimple sexypurple"  value="Add project" />   
                </form> 
            <?php // } ?>
         </th>       
<?php } ?>      
        <th class="th3">   
            <input type="hidden" id="year" value="<?php echo $this->year; ?>" />
            <input type="hidden" id="month" value="<?php echo $this->month; ?>" />
        </th>
    </tr>  
     
 </table>
    
    <br /> <br />
    
 <table <?php echo 'print' == $this->views ? 'width="90%"' :'' ?>>   
    <tr class="th1">
        <th class="left" colspan="2">
        </th>
        <?php for($i = 1; $i <= $this->endDay; $i++)
        {
        ?>
        <th class="project_name middle <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php echo date('D', strtotime($this->year . '-' .  $this->month . '-' . $i)); ?> </th>
        <?php 
        }
        ?>
        <th class="right"></th>
    </tr>
    
    <tr  class="th2">
        <th class="left" colspan="2">
        </th>
        <?php for($i = 1; $i <= $this->endDay; $i++)
        {
        ?>
        <th  class="middle <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php echo $i; ?></th>
        <?php 
        }
        ?>
        <th class="project_name right">Totaal</th>
    </tr>    
    <?php 
//   print_r($this->allProject);
        foreach($this->allProject as $project)
        {
//        	    print_r($project);
            $tr = 0;
    ?>
    <tr >
        <td class="project_name left td1">
            <?php echo $project['project_num']; ?>
        </td>
        <td class="project_name middle td1">
            <?php echo $project['name']; ?>
        </td>
	        <?php for($i = 1; $i <= $this->endDay; $i++)
	        {
		        if ((1 != $project['base']))
		        {	
		        	$aStartDate       = explode('-', $project['start_date']);
		        	(int) $startDay   = $aStartDate[2];
		        	
		        	$aEndDate         = explode('-', $project['end_date']);
	                (int) $endDay     = $aEndDate[2];
	                (int) $endYear    = $aEndDate[0];
	                
//	                print_r($aEndDate);
	                
	                if($aStartDate[1] != $aEndDate[1])
	                {
	                	$endDay   = $this->endDay;
	                }
	                
	                if('0000-00-00' == $project['start_date'])
	                {
	                	$startDay = 1;
	                }
	                
		            if('0000-00-00' == $project['end_date'])
                    {
                        $endDay   = $this->endDay;
                    }
                    
                    if($endYear >  $this->year)
                    {
                        $endDay   = $this->endDay;
                    }
		        }
		        else
		        {
		        	$startDay = 1;
		        	$endDay   = $this->endDay;
		        }   
	        	
	        ?>
	    <td  class="middle project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php
//            echo "s- $startDay   e-$endDay";
	           if (($i >= $startDay && $i <= $endDay) || (1 == $project['base'])) 
	           {
	           	   $val = '';
	           	   if (isset($allReport[$i]))
	           	       if (isset($allReport[$i][$project['id']]))
	           	           $val = $allReport[$i][$project['id']] ;
	           	           
	           	   $status = 'close' == $this->reportPeriod['status'] ? 'readonly="readonly"' : '' ;
	           	   if ('print' != $this->views) 
	           	   {        
	           	   	   if ('close' != $this->reportPeriod['status'])
	           	   	   {
	                       echo '<input class="w_20 hour ' . (1 == $project['billable'] ? 'billable' : 'free') . '" project="' . $project['id'] . '" day="' . $i . '" id="' . $i . '_' . $project['id'] . '" value="' . $val . '" ' .  $status . ' />';
	           	   	   }
	           	   	   else
	           	   	   {
	           	   	   	   if ('' == $val)
	           	   	   	   {
	           	   	   	   	   $val1 = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	           	   	   	   }
	           	   	   	   else
	           	   	   	   {   
	           	   	   	   	   $val1 = $val;
	           	   	   	   }
	           	   	   	   echo '<em class="close_period">&nbsp;' . $val1 . '&nbsp;</em>';
	           	   	   }
	           	   }
	           	   else
	           	   {
	           	   	   echo $val;
	           	   }
	           	   
	               $tr += $val;

	               if (isset($total[$i]))
                        $total[$i] += $val;
                   else
                        $total[$i] = $val;
	           } 
	        ?>
        </td>
	        <?php 
	        }
	        ?>
            <td class="project_name right"> <em class="w_20 sum_total" project="<?php echo $project['id']; ?>" id="tr_<?php echo $project['id']; ?>" ><?php echo number_format($tr, 1, '.', ''); ?> </em></td>
    </tr>
    <?php 
        }
    ?>
    
        <tr >
        <td class="left td1" colspan="2"></td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="middle <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>"><?php

                   echo '&nbsp;';
            ?>
        </td>
            <?php 
            }
            ?>
        <td class="right"></td>    
    </tr>
    
    <tr >
        <td class="left td1"></td>
        <td class="middle project_name td1">Billable hours: </td>
       
            <?php 
//             print_r($total);
            
            for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="middle project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>">&nbsp;<?php

                   if ('print' != $this->views) 
                   {  
                       if ('close' == $this->reportPeriod['status'])
                       {
                           $ct =  $total[$i] <= 8 ? $total[$i] != 0 ? $total[$i] : '' : 8;
                           echo number_format($ct, 1, '.', '') ;
                           $all_total += $ct;
                       }
                       else
                       {
                            echo '<em class="w_20 total" day="' . $i . '" id="total_' . $i . '" /> ';
                       }
                   }
                   else
                   {
                        $ct =  $total[$i] <= 8 ? $total[$i] != 0 ? $total[$i] : '' : 8;
                        echo number_format($ct, 1, '.', '') ;
                        $all_total += $ct;
                   }
            ?>
        </td>
            <?php 
            }
            ?>
        <td class="project_name right">&nbsp;
            <?php
                    if ('print' != $this->views) 
                    {  ?><em class="w_20" id="all_total" ><?php  echo number_format($all_total, 1, '.', ''); ?> </em>
                    
            <?php
                    }
                    else
                    {
                        echo number_format($all_total, 1, '.', ''); 
                    }?></td>
    </tr>
    
    <tr >
        <td class="left td1"></td>
        <td class="middle project_name td1">Billable overtime: </td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="middle project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>">&nbsp;<?php
                   if ('print' != $this->views) 
                   {  
                   	   if ('close' == $this->reportPeriod['status'])
                       {
                       	    $cot =   $total[$i] > 8 ? $total[$i] - 8 : '';
                            echo number_format($cot, 1, '.', '');
                            $all_overtime += $cot;
                       }
                       else
                       {
                            echo '<em class="w_20" day="' . $i . '" id="overtime_' . $i . '" />';
                       }
                   }
                   else
                   {
                        $cot =   $total[$i] > 8 ? $total[$i] - 8 : '';
                        echo number_format($cot, 1, '.', '');
                        $all_overtime += $cot;
                   }
            ?>
        </td>
            <?php 
            }
            ?>
        <td class="project_name right">&nbsp;
            <?php
                    if ('print' != $this->views) 
                    {  ?><em class="w_20" id="all_overtime" ><?php echo number_format($all_overtime, 1, '.', ''); ?></em>
                    
            <?php
                    }
                    else
                    {
                        echo number_format($all_overtime, 1, '.', ''); 
                    }?></td>
    </tr> 
    <tr >
        <td class="left td1"></td>
        <td class="middle project_name td1">Total billable: </td>
            <?php for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="middle project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>">&nbsp;<?php
                   if ('print' != $this->views) 
                   {  
                   	   if ('close' == $this->reportPeriod['status'])
                       {
                            $cot =   $total[$i];
                            echo number_format($cot, 1, '.', '');
                            $sum_total += $cot;
                       }
                       else
                       {
                            echo '<em class="w_20" day="' . $i . '" id="sum_total_' . $i . '" />';
                       }
                   }
                   else
                   {
                        $cot =   $total[$i];
                        echo number_format($cot, 1, '.', '');
                        $sum_total += $cot;
                   }
            ?>
        </td>
            <?php 
            }
            ?>
        <td class="project_name right">&nbsp;
            <?php
                    if ('print' != $this->views) 
                    {  ?><em class="w_20" id="sum_total" ><?php echo number_format($sum_total, 1, '.', ''); ?></em>
                    
            <?php
            
                    }
                    else
                    {
                        echo number_format($sum_total, 1, '.', ''); 
                    }?></td>
    </tr>        
    
    <tr >
        <td class="left td1"></td>
        <td class="middle project_name td1">Non-billable hours: </td>
            <?php 
            $sum_free = 0;
            for($i = 1; $i <= $this->endDay; $i++)
            {
            
            ?>
        <td  class="middle project_name <?php if (
            6 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i)) || 
            0 == date('w', strtotime($this->year . '-' .  $this->month . '-' . $i))) 
            echo 'pink';?>">&nbsp;<?php
                       if ('close' == $this->reportPeriod['status'])
                       {
                            $cot =   $total[$i];
                            echo number_format($cot, 1, '.', '');
                            $sum_free += $cot;
                       }
                       else
                       {
                            echo '<em class="w_20" day="' . $i . '" id="sum_free_' . $i . '" />';
                       }
            ?>
        </td>
            <?php 
            }
            ?>
        <td class="project_name right">&nbsp;
            <?php
                    if ('print' != $this->views) 
                    {  ?><em class="w_20" id="sum_free" ><?php echo number_format($sum_free, 1, '.', ''); ?></em>
                    
            <?php
                    }
            ?>
		</td>
    </tr>        

</table>

 <?php if ('print' != $this->views ) {?>   
 <br /><br /><br />
    <table border="0">
     <tr>
     <td colspan="3" class="project_name">  
        <form action="/index/attach" enctype="multipart/form-data" method="post">
            <input type="hidden" name="id_user" value="<?php echo $this->user->id; ?>" />
            <input type="hidden" name="do_action" value="attach" />
            <input type="hidden" name="year" value="<?php echo $this->year; ?>" />
            <input type="hidden" name="month" value="<?php echo $this->month; ?>" />
            <input type="file"   name="file_name" id="file_name" maxlength="255"  />          
            <input type="submit" class="sexybutton sexysimple sexygreen"  value="Attach timesheet" />   
        </form> 
     </td>
     <td> &nbsp; &nbsp;</td>
     <td><?php 
            if (isset($this->attach))
            {
        ?>
                <font color="red">Timesheet already exists. Loading new timesheet removes the old.</font>
        <?php 
            }?></td>
     </tr>
   </table> 
 <?php } ?>
 
 
     <br /><br />

<?php  if ('print' == $this->views) 
{ ?>
<div class="clear"></div>
<?php  if ('print' == $this->viewss) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_3 alpha omega border2">Handtekening medewerker: <br /><br /><br /><br /></div>
<?php //if ('print' == $this->view) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_3 alpha omega border2">Handtekening opdrachtgever: <br /><br /><br /><br /></div>
<?php //if ('print' == $this->view) 
{ ?>
<div class="grid_1 alpha omega"> &nbsp; </div>
<?php } ?>
<div class="grid_<?php echo 'print' == $this->views ? '3' : '2'?> alpha omega border2">Opmerkingen: <br /><br /><br /><br /></div>

<div class="clear"></div>
<br /><br /><br />   
<script type="text/javascript">
$(function()
{
	window.print();
});
</script>

<?php }?>